package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyCommunityUnitVo;
import com.ruoyi.system.bo.ZsyyCommunityUnitQueryBo;
import com.ruoyi.system.bo.ZsyyCommunityUnitAddBo;
import com.ruoyi.system.bo.ZsyyCommunityUnitEditBo;
import com.ruoyi.system.service.IZsyyCommunityUnitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 小区单元管理Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "小区单元管理控制器", tags = {"小区单元管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/communityUnit")
public class ZsyyCommunityUnitController extends BaseController {

    private final IZsyyCommunityUnitService iZsyyCommunityUnitService;

    /**
     * 查询小区单元管理列表
     */
    @ApiOperation("查询小区单元管理列表")
    @PreAuthorize("@ss.hasPermi('system:communityUnit:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyCommunityUnitVo> list(@Validated ZsyyCommunityUnitQueryBo bo) {
        return iZsyyCommunityUnitService.queryPageList(bo);
    }
    /**
     * 根据小区id获取单元列表
     */
    @ApiOperation("根据小区id获取单元列表")
    @GetMapping("/getListByCommunity")
    public AjaxResult getListByCommunity(@Validated ZsyyCommunityUnitQueryBo bo) {
        return AjaxResult.success(iZsyyCommunityUnitService.getListByCommunity(bo));
    }

    /**
     * 导出小区单元管理列表
     */
    @ApiOperation("导出小区单元管理列表")
    @PreAuthorize("@ss.hasPermi('system:communityUnit:export')")
    @Log(title = "小区单元管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyCommunityUnitVo> export(@Validated ZsyyCommunityUnitQueryBo bo) {
        List<ZsyyCommunityUnitVo> list = iZsyyCommunityUnitService.queryList(bo);
        ExcelUtil<ZsyyCommunityUnitVo> util = new ExcelUtil<ZsyyCommunityUnitVo>(ZsyyCommunityUnitVo.class);
        return util.exportExcel(list, "小区单元管理");
    }

    /**
     * 获取小区单元管理详细信息
     */
    @ApiOperation("获取小区单元管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:communityUnit:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyCommunityUnitVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZsyyCommunityUnitService.queryById(id));
    }

    /**
     * 新增小区单元管理
     */
    @ApiOperation("新增小区单元管理")
    @PreAuthorize("@ss.hasPermi('system:communityUnit:add')")
    @Log(title = "小区单元管理", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyCommunityUnitAddBo bo) {
        return toAjax(iZsyyCommunityUnitService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改小区单元管理
     */
    @ApiOperation("修改小区单元管理")
    @PreAuthorize("@ss.hasPermi('system:communityUnit:edit')")
    @Log(title = "小区单元管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyCommunityUnitEditBo bo) {
        return toAjax(iZsyyCommunityUnitService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除小区单元管理
     */
    @ApiOperation("删除小区单元管理")
    @PreAuthorize("@ss.hasPermi('system:communityUnit:remove')")
    @Log(title = "小区单元管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZsyyCommunityUnitService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
